home *** CD-ROM | disk | FTP | other *** search
-
- -- Characters strings
-
- expanded class interface STRING
- creation procedures
- make (n:INTEGER)
- -- Allocate space for at least 'n' characters.
- require
- non_negative_size: n >= 0
- ensure
- capacity = n
- exported features
- append (s:STRING)
- -- Append a copy of 's' at end of current string.
- require
- argument_not_void: s /= Void
- ensure
- count = old count + s.count
- capacity:INTEGER
- -- Number of characters that can be contained in the string
- clear
- -- Clear out string.
- ensure
- count = 0
- copy (other:STRING)
- -- Reinitialize with copy of 'other'
- require
- other /= Void
- ensure
- count = other.count;
- -- For all i: 1..count, item (i) = other.item (i)
- count:INTEGER
- -- Actual number of characters making up the string
- ensure
- Result >= 0
- empty:BOOLEAN
- -- Is string empty?
- extend (c:CHARACTER)
- -- Add 'c' at end.
- ensure
- count = old count + 1
- fill_blank
- -- Fill with blanks.
- ensure
- -- For all i: 1..count, item (i) = Blank
- hash_code:INTEGER
- -- Hash code value of current string
- head (n:INTEGER)
- -- Remove all characters except for the first 'n';
- -- do nothing if n >= count.
- require
- non_negative_argument: n >= 0
- ensure
- -- count = min (n,old count)
- index_of (c:CHARACTER; i:INTEGER):INTEGER
- -- Index of the first occurence of 'c', starting at
- -- position i; 0 if not found.
- require
- index_large_enough: i >= 1;
- index_small_enough: i <= count
- ensure
- Result = 0 or item (Result) = c
- is_equal (other:STRING):BOOLEAN
- -- Is current string made of the same characters sequence as 'other'?
- -- (Redefined from 'ANY')
- item (i:INTEGER):CHARACTER
- -- Character at position 'i'
- require
- index_large_enough: i >= 1;
- index_small_enough: i <= count
- item_code (i:INTEGER):INTEGER
- -- Numeric code of character at position 'i'
- require
- index_large_enough: i >= 1;
- index_small_enough: i <= count
- lef_adjust
- -- Remove leading blanks.
- -- NOT IMPLEMENTED.
- ensure
- (count /= 0) implies (item (1) /= ' ')
- precede(c:CHARACTER)
- -- Add 'c' at front.
- -- NOT IMPLEMENTED.
- ensure
- count = old count + 1
- prepend(s:STRING)
- -- Prepend a copy of 's' at front of current string.
- -- NOT IMPLEMENTED.
- require
- argument_not_void: s /= Void
- ensure
- count = old count + s.count
- put (c:CHARACTER; i:INTEGER)
- -- Replace by 'c' character at position 'i'.
- require
- index_large_enough: i >= 1;
- index_small_enough: i <= count
- ensure
- item (i) = c
- remove (i:INTEGER)
- -- Remove i-th character.
- -- NOT IMPLEMENTED.
- require
- index_large_enough: i >= 1;
- index_small_enough: i <= count
- ensure
- count = old count - 1
- remove_all_occurrences (c:CHARACTER)
- -- Remove all occurrences of 'c'.
- -- NOT IMPLEMENTED.
- ensure
- -- For all i: 1..count, item (i) /= c
- -- count = old count - number of occurrences of 'c' in initial string
- right_adjust
- -- Remove trailing blanks.
- -- NOT IMPLEMENTED.
- ensure
- count /= 0 implies item (count) /= ' '
- shrink (s:STRING; n1,n2:INTEGER)
- -- Remove characters outside of interval n1..n2
- -- NOT IMPLEMENTED.
- require
- argument_not_void: s /= Void
- meaningful_origin: 1 <= n1;
- meaningful_interval: n1 <= n2;
- meaningful_end: n2 <= s.count
- ensure
- is_equal (s.substring (n1, n2))
- substring (n1, n2:INTEGER):STRING
- -- Copy of substring of current string containing all characters
- -- at indices between n1 and n2.
- -- NOT IMPLEMENTED.
- require
- meaningful_origin: 1 <= n1;
- meaningful_interval: n1 <= n2;
- meaningful_end: n2 <= count
- ensure
- Result.count = n2 - n1 +1
- -- For all i: 1..n2-n1, Result.item(i) = item (n1 +i -1)
- tail (n:INTEGER)
- -- Remove all characters except for the last 'n';
- -- do nothing if n >= count.
- -- NOT IMPLEMENTED.
- require
- non_negative_argument: n >= 0
- ensure
- -- count = min (n,old count)
- to_integer:INTEGER
- -- Integer value of current string, assumed to contain digits only
- -- When applied to "123", will yield 123.
- require
- -- String contains digits only
- to_lower
- -- Convert string to lower case.
- to_upper
- -- Convert string to upper case.
- invariant
- 0 <= count; count <= capacity
- end interface -- class 'STRING'
-
-